#coding=utf-8
'''
# @Name:logTest
# @author:mysouil
# @Description:
# @DATE:2022/9/22 11:00
# @Modified By:
'''

# coding=utf-8
import logging

# 这是第一次日志，没设置日志的各个参数
logging.error("1")


def init_logging():
    """
        初始化logging环境
        hdlr = TimedRotatingFileHandler(filename, "D", 1, 10)
        表示：设置每天自动切换到一个文件下保存，一共保存10天的数据...
        hdlr = TimedRotatingFileHandler(filename, "D", 1, 0)
        表示：设置每天自动切换到一个文件下保存，保存无限天数...
        “S”: Seconds
        “M”: Minutes
        “H”: Hours
        “D”: Days
         1 : 表示单位...
         10: 表示保存的单位....
    """
    import sys
    import logging.handlers
    from logging.handlers import TimedRotatingFileHandler
    
    root = logging.getLogger()
    level = logging.INFO
    filename = "log/chanzai.log"
    
    formatter = logging.Formatter('%(asctime)s %(filename)s-%(lineno)d [%(levelname)s] %(message)s')
    
    hdlr = TimedRotatingFileHandler(filename, "midnight", 1, 15)
    hdlr.setFormatter(formatter)
    root.addHandler(hdlr)
    root.setLevel(level)
    # 同时输出到屏幕，便于实施观察
    handle2 = logging.StreamHandler(sys.stdout)
    handle2.setFormatter(formatter)
    root.addHandler(handle2)


# 初始化日志配置
init_logging()

# 第二次日志
logging.error("2")


